We need to have “blank maps” to color in as thematic maps, and optionally spatial data (points, lines) to add. Two sources:

  1. Dowloaded file [focus here].
  2. Provided through an R-package [see other workshop.

Various formats for spatial data possible: Shapefile, GeoJSON, KML, GPX-tracks, etc.

Recommended: Use st_read() function from the sf library, as it returns a spatial feature object and is based on GDAL: hard to find a format not covered.

Points of attention:

  • We want sf-objects. Frequently already in the right format, if not convert using st_as_sf().
  • Pay attention to included identifier for merging.
# load general packages used below
library(dplyr)   # tidyverse datamanipulation library
library(sf)      # tidyverse spatial features library
library(janitor) # utility function clean_names()
library(mapview)
library(tmap)
library(here)

Example: load railway tracks

raillines <- st_read(here('data/source/census_1851_raillines/1851EngWalesScotRail_Lines.shp'))
mapview(raillines)
qtm(raillines)

Example: load cencus districts

districts_spatial <- st_read(here('data/source/census_1851_districts/1851EngWalesRegistrationDistrict.shp'))
mapview(districts_spatial)
qtm(districts_spatial)